package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
  @Autowired
  private NursingLevelMapper nursingLevelMapper;
  @Override
  public NursingLevelVo listAll() {
    NursingLevelVo nursingLevelVo =nursingLevelMapper.getAll();
    return nursingLevelVo;
  }

  @Override
  public void add(NursingLevelDto nursingLevelDto) {
    NursingLevel nursingLevel = new NursingLevel();
    BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
    nursingLevel.setUpdateTime(LocalDateTime.now());
    nursingLevel.setUpdateBy(1l);
    nursingLevel.setCreator("1");
    nursingLevelMapper.add(nursingLevel);
  }

  @Override
  public PageResponse<NursingLevelVo> getList(Integer pageNum, Integer pageSize, String name, Integer status) {
    PageHelper.startPage(pageNum, pageSize);
    Page<NursingLevel> nursingLevelPage = nursingLevelMapper.selectByPage(name, status);
    PageResponse<NursingLevelVo> levelVoPageResponse = PageResponse.of(nursingLevelPage, NursingLevelVo.class);
    return levelVoPageResponse;
  }

  @Override
  public NursingLevelVo getById(String id) {
    NursingLevelVo nursingLevelVo =nursingLevelMapper.getById(id);
    return nursingLevelVo;
  }

  @Override
  public void update(NursingLevelDto nursingLevelDto) {
    nursingLevelDto.setUpdateTime(LocalDateTime.now());
    nursingLevelDto.setUpdateBy(1l);
    nursingLevelDto.setCreator("1");
    nursingLevelMapper.update(nursingLevelDto);
  }

  @Override
  public void deleteById(String id) {
    nursingLevelMapper.deleteById(id);
  }

  @Override
  public void isActive(String id, Integer status) {
    nursingLevelMapper.isActive(id,status);
  }
}
